package dwl;

import static org.junit.Assert.assertTrue;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IBulletSnapshot;
import robocode.control.snapshot.ITurnSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that the robot
 * fires bullets with a power between 0.9 and 3.
 * 
 * @author David Lin
 */
public class TestBulletPower extends RobotTestBed {

  /**
   * Specifies that RobotFighter and SpinBot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SpinBot,dwl.RobotFighter";
  }

  /**
   * This test runs for 1 round.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 1;
  }

  /**
   * After each turn, check for bullets on battlefield fired by RobotFighter.
   * @param event Info about the current state of the battle.
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    ITurnSnapshot turn = event.getTurnSnapshot();
    IBulletSnapshot[] bullets = turn.getBullets();
    
    for (int i = 0; i < bullets.length; i++) {
      assertTrue("Bullet power >= 0.25", bullets[i].getPower() >= 0.25);
    }
  }
}
